<?php
class SettingController extends BaseAdminController
{
	public function actionIndex()
	{
		$file_config = Yii::app()->getBasePath().'/config/config.txt';
		if(isset($_POST['Setting'])){
			$configtext = '';
			foreach ($_POST['Setting'] as $key => $value){
				$configtext .= $key.'{:}'.$value."\n";
			}
			$fh = fopen($file_config, 'w') or die("can't open file");
			fwrite($fh, $configtext);
			fclose($fh);
			Yii::app()->user->setFlash('msg','Setting saved successful!');
		}
		$data = Common::ReadConfig();
		$this->render('index', array('data'=>$data));
	}
	public function actionMail()
	{
		$file_config = Yii::app()->getBasePath().'/config/config.txt';
		if(isset($_POST['Setting'])){
			$configtext = '';
			foreach ($_POST['Setting'] as $key => $value){
				$configtext .= $key.'{:}'.$value."\n";
			}
			$fh = fopen($file_config, 'w') or die("can't open file");
			fwrite($fh, $configtext);
			fclose($fh);
			Yii::app()->user->setFlash('msg','Setting saved successful!');
		}
		$data = Common::ReadConfig();
		$this->render('mail', array('data'=>$data));
	}
}